object BasicFunctionDemo extends App{
  //1.无参数无返回的函数
  def printWelcomeMessage(): Unit = {
    println("=====学生信息查询系统=====")
    println("欢迎使用学生信息查询功能")
    println("======================")
  }
  //2.有参数有返回值的函数：根据学号查询学生姓名
  def getStudentName(studentId:String): String = {
    //模拟数据库查询
    val studentMap = Map(
      "S2025001" -> "张三",
      "S2025002" -> "李四",
      "S2025003" -> "王五",
      "S2025004" -> "赵六",
    )
    studentMap.getOrElse(studentId,"未知学生")
  }
  //3.有多个参数的函数：计算平均分
  def calculateAverageScore(score: List[Int]): Double = {
    if (score.isEmpty) 0.0
    else score.sum.toDouble / score.size
  }
  //4.调用函数
  printWelcomeMessage()

  val studentId = "S2025002"
  val studentName = getStudentName(studentId)
  println(s"\n学生 $studentId 的姓名是$studentName")

  val mathScore = List(85,92,88,90,86)
  val avg = calculateAverageScore(mathScore)
  println(s"该学生的数学平均分是$avg")

  //5.函数可以直接作为表达式使用
  println(s"平均分是否及格：${calculateAverageScore(mathScore) >= 60}")
}
